home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / hash.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-21  |  3.0 KB  |  82 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  hash.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17. //------------------------------------------------------------------------------
  18. //
  19. // hash  (data structure: hashing with chaining)
  20. //
  21. // Stefan Naeher (1989)
  22. //
  23. //------------------------------------------------------------------------------
  24.  
  25. #ifndef HASHH
  26. #define HASHH
  27.  
  28. #include <LEDA/ch_hashing.h>
  29.  
  30. typedef ch_hashing_el* hash_item;
  31.  
  32. #define hash(keytype,infotype) name3(keytype,infotype,hash)
  33.  
  34. #define HFCT(keytype,infotype) name3(keytype,infotype,_hashfct)
  35.  
  36. #define HFCTC(keytype,infotype) name3(keytype,infotype,_const_hashfct)
  37.  
  38. #define hashdeclare2(keytype,infotype)\
  39. \
  40. typedef int (*HFCT(keytype,infotype))(keytype&);\
  41. typedef int (*HFCTC(keytype,infotype))(const keytype&);\
  42. \
  43. struct hash(keytype,infotype) : public ch_hashing {\
  44. \
  45. int  cmp(ent& x, ent& y) const { return compare(*(keytype*)&x,*(keytype*)&y); }\
  46. void clear_key(ent& x)   const { Clear(*(keytype*)&x); }\
  47. void clear_inf(ent& x)   const { Clear(*(infotype*)&x); }\
  48. void copy_key(ent& x)    const { Copy(*(keytype*)&x); }\
  49. void copy_inf(ent& x)    const { Copy(*(infotype*)&x); }\
  50. void print_key(ent& x)   const { Print(*(keytype*)&x); }\
  51. \
  52. int        defined(keytype y) const { return ch_hashing::member(Ent(y)); }\
  53. hash_item  lookup(keytype y)  const { return ch_hashing::lookup(Ent(y)); }\
  54. void       change_inf(hash_item it, infotype i)\
  55.                                     { ch_hashing::change_inf(it,Ent(i)); }\
  56. hash_item  insert(keytype y,infotype x)\
  57.                                     { return ch_hashing::insert(Ent(y),Ent(x));}\
  58. void      del(keytype y)            { delete ch_hashing::del(Ent(y)); } \
  59. void      del_item(hash_item it)    { del(key(it)); } \
  60. keytype   key(hash_item it)   const { return keytype(ch_hashing::key(it)); }\
  61. infotype  inf(hash_item it)   const { return infotype(ch_hashing::inf(it)); } \
  62. infotype  info(hash_item it)  const { return infotype(ch_hashing::inf(it)); } \
  63. \
  64. hash(keytype,infotype)()                                                    {}\
  65. hash(keytype,infotype)(int s)                            :ch_hashing(s)               {}\
  66. hash(keytype,infotype)(HFCT(keytype,infotype) f)         :ch_hashing(hash_fct(f))     {}\
  67. hash(keytype,infotype)(HFCTC(keytype,infotype) f)        :ch_hashing(hash_fct(f))     {}\
  68. hash(keytype,infotype)(int s, HFCT(keytype,infotype) f)  :ch_hashing(s,hash_fct(f))   {}\
  69. hash(keytype,infotype)(int s, HFCTC(keytype,infotype) f) :ch_hashing(s,hash_fct(f))   {}\
  70. ~hash(keytype,infotype)()   { remove(); }\
  71. } ;
  72.  
  73.  
  74. // ----------------------------------------------------------------
  75. // iteration
  76. // ----------------------------------------------------------------
  77.  
  78. #define forall_hash_items(i,D) for((D).init_iterator(); i=(D).move_iterator();)
  79.  
  80. #endif
  81.